<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="startDate">
              <a-input :disabled=formDisabled v-model="model.startDate" :max-length="36"  placeholder="请输入开始时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endDate">
              <a-input :disabled=formDisabled v-model="model.endDate" :max-length="36"  placeholder="请输入结束时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="差异数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="differenceCount">
              <a-input :disabled=formDisabled v-model="model.differenceCount" :max-length="36"  placeholder="请输入差异数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="金蝶流水id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kingdeeFid">
              <a-input :disabled=formDisabled v-model="model.kingdeeFid" :max-length="36"  placeholder="请输入金蝶流水id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="金蝶银行流水表id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billId">
              <a-input :disabled=formDisabled v-model="model.billId" :max-length="36"  placeholder="请输入金蝶银行流水表id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否同步成功" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isSuccess">
              <a-input :disabled=formDisabled v-model="model.isSuccess" :max-length="36"  placeholder="请输入是否同步成功"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="失败原因" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="errorMsg">
              <a-input :disabled=formDisabled v-model="model.errorMsg" :max-length="36"  placeholder="请输入失败原因"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
  import moment from 'moment'
  import { mapGetters } from 'vuex'

  export default {
    name: 'ErpFinanceKingdeeBankStatementAsyncLogForm',
    components: {
      SelectUserByDep,
      SelectTeamInput,
      SelectCompanyInput,
      SelectCustomerInput
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/api/erp/finance/kingdee/log/erpFinanceKingdeeBankStatementAsyncLog/add",
          edit: "/api/erp/finance/kingdee/log/erpFinanceKingdeeBankStatementAsyncLog/edit",
          queryById: "/api/erp/finance/kingdee/log/erpFinanceKingdeeBankStatementAsyncLog/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      ...mapGetters(['userInfo']),
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.$refs.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
                that.$emit('unButtonDisable');
              }
            }).catch((error)=>{
               that.$emit('unButtonDisable');
             }).finally(() => {
               that.confirmLoading = false;
             })
          }else {
           that.$emit('unButtonDisable');
          }

        })
      },
    }
  }
</script>
